﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AV;

namespace iSchema
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void OnFormLoaded(object sender, EventArgs e)
        {
            this.Text = Settings.NameVersion;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("    uid:");
            sb.AppendLine("        uid:        varchar");
            sb.AppendLine("        company_id: integer");
            sb.AppendLine("        created_at: timestamp");
            sb.AppendLine("        nick:       varchar");
            sb.AppendLine("        vcard_id:   integer");
            this.txtJavaSchema.Text = sb.ToString();
        }

        private void OnConvertButtonClicked(object sender, EventArgs e)
        {
            try
            {
                string[] arLines = txtJavaSchema.Lines;
                if( (arLines != null) && (arLines.Length > 1) )
                {
                    SchemaClass sc = SchemaClass.Parse(arLines);
                    string classDef = SchemaClass.CreateClassStructure(sc);
                    Log4cs.Log(classDef);
                    classDef = classDef.Replace("\t", "    ");
                    classDef = classDef.Replace('[', '{');
                    classDef = classDef.Replace(']', '}');
                    this.txtOutputJava.Text = classDef;
                }
            } catch(Exception ex)
            {
                Log4cs.Log(Importance.Error, "Error parsing Java schema!");
                Log4cs.Log(Importance.Debug, ex.ToString());
            }
        }

    }
}
